package com.weichuanbo.xwdz.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.weichuanbo.xwdz.R;
import com.weichuanbo.xwdz.di.component.DaggerPhoneLoginComponent;
import com.weichuanbo.xwdz.di.module.UserModule;
import com.weichuanbo.xwdz.mvp.contract.UserContract;
import com.weichuanbo.xwdz.mvp.presenter.UserPresenter;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author : ssy
 * @date : 2018/9/3 18:07
 * @E-Mail ：1161209667@qq.com
 */
public class PhoneLoginActivity extends BaseActivity<UserPresenter> implements UserContract.View {
    @BindView(R.id.tv_phone_remind)
    TextView tvPhoneRemind;
    @BindView(R.id.et_msg_code)
    EditText etMsgCode;
    @BindView(R.id.tv_get_code)
    TextView tvGetCode;
    @BindView(R.id.tv_login)
    TextView tvLogin;
    private String phone;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        //如找不到该类,请编译一下项目
        DaggerPhoneLoginComponent
                .builder()
                .appComponent(appComponent)
                .userModule(new UserModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.activity_phone_login;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        phone = getIntent().getStringExtra("phone");
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
    @OnClick({R.id.iv_back, R.id.tv_get_code, R.id.tv_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_get_code:
                mPresenter.getCode(phone);
                break;
            case R.id.tv_login:
                mPresenter.login(phone,etMsgCode.getText().toString());
                break;
        }
    }
}
